package com.zf.bm.common.core.sys.dao;


import com.zf.bm.common.core.base.dao.BaseDao;
import com.zf.bm.common.core.sys.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

/**
 * 用户DAO接口
 */
public interface UserDao extends BaseDao<User> {


    /**
     * 删除用户角色关联数据
     * @return
     */

    @Delete("DELETE FROM sys_user_role WHERE user_id = #{id}")
    int deleteUserRole(Long id);

    /**
     * 插入用户角色关联数据
     *
     * @param user
     * @return
     */
    int insertUserRole(User user);

    @Select("select count(1) FROM sys_user_role r\n" +
            "inner join (select id from sys_user where del_flag = '0') u on r.user_id = u.id\n" +
            "WHERE role_id = #{roleId} ")
    Long countUserRole(Long roleId);

    @Select("SELECT a.remarks FROM sys_role a LEFT JOIN sys_user_role b ON a.ID = b.role_id LEFT JOIN sys_user c ON b.user_id = c.ID where c.login_name = #{loginName}")
    String getRoleByLoginName(String loginName);
}
